<template>
  <el-dialog
    custom-class="custom-dialog"
    class="border"
    :width="width"
    :title="title"
    append-to-body
    :close-on-click-modal="clickClose"
    :close-on-press-escape="pressEscape"
    :destroy-on-close="closeFree"
    v-model="_value"
  >
    <slot></slot>
    <template #footer v-if="showFooter">
      <el-button size="small" @click="handelCancel">{{ cancelText }}</el-button>
      <el-button size="small" type="primary" @click="handelOk">{{ okText }}</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { computed } from "vue";

const emit = defineEmits(["update:modelValue", "ok", "cancel"]);

const props = defineProps({
  title: {
    type: String,
    default: ""
  },
  width: {
    type: String,
    default: "50%"
  },
  modalValue: {
    type: Boolean,
    default: false
  },
  clickClose: {
    type: Boolean,
    default: false
  },
  pressEscape: {
    type: Boolean,
    default: false
  },
  closeFree: {
    type: Boolean,
    default: false
  },
  showFooter: {
    type: Boolean,
    default: true
  },
  cancelText: {
    type: String,
    default: "取 消"
  },
  okText: {
    type: String,
    default: "确 定"
  },
  border: {
    type: Boolean,
    default: true
  }
});

const _value = computed({
  get() {
    return props.modalValue;
  },
  set(val) {
    emit("update:modelValue", val);
  }
});

const handelOk = () => {
  emit("ok");
};
const handelCancel = () => {
  _value.value = false;
  emit("cancel");
};
</script>

<style lang="scss" scoped>
:deep(.custom-dialog) {
  .el-dialog__header {
    padding: 10px 20px;
    .el-dialog__title {
      font-size: 17px;
    }
    .el-dialog__headerbtn {
      top: 15px;
      .i {
        font-size: large;
      }
    }
  }

  .el-dialog__footer {
    padding: 10px 20px;
  }
}

.border {
  :deep(.el-dialog__header) {
    border-bottom: 1px solid #e8e8e8;
  }
  :deep(.el-dialog__body) {
    padding: 20px;
  }
  :deep(.el-dialog__footer) {
    border-top: 1px solid #e8e8e8;
  }
}
</style>
